package com.foreveross.proxyip;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.foreveross.crawl.common.InstanceFactory;
import com.foreveross.crawl.common.cfg.PropertyUtils;
/**
 * 代理ip提供类工厂
 * <p>通过属性文件配置项，实例化代理ip提供类
 * @author xiangsf 2013-1-3
 * 
 *
 */
public class ProxyIpProviderFactory {

	public static Log logger= LogFactory.getLog(ProxyIpProviderFactory.class);
	
	public static IProxyIpProvider getDefaultProxyProvider(){
		Object obj = null;
		try {
			String className = PropertyUtils.getProperty(ProxyipProperties.PROXY_IP_PROVIDER_CLASS, ProxyipProperties.CONFIG_FILE);
			String isEnble = PropertyUtils.getProperty(ProxyipProperties.PROXY_IP_PROVIDER_ENABLE, ProxyipProperties.CONFIG_FILE);
			
			if(StringUtils.isNotBlank(className)){
				if (Boolean.valueOf(isEnble)) {
					obj = InstanceFactory.getInstance(Class.forName(className));
				} else {
					obj = Class.forName(className).newInstance();
				}
			}
		} catch (Exception e) {
			logger.error(e);
		}
		return (IProxyIpProvider)obj;
	}
}
